package com.zheng.rpc.loadbalance;

import java.util.List;

public abstract class AbstractLoadBalance implements LoadBalance {
    @Override
    public String selectServiceAddress(List<String> serviceAddresses, String serviceName) {
        if (serviceAddresses.isEmpty()) {
            return null;
        }
        if (serviceAddresses.size() == 1) {
            return serviceAddresses.get(0);
        }
        return doSelect(serviceAddresses, serviceName);
    }

    /**
     * 负载均衡算法
     * @param serviceAddresses
     * @param serviceName
     * @return
     */
    protected abstract String doSelect(List<String> serviceAddresses, String serviceName);
}
